package com.wxzz.elearing.user.api.admin;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.*;
import com.wxzz.elearing.user.entity.*;
import com.wxzz.elearing.user.service.IDocentService;
import com.wxzz.elearning.common.exception.ServiceException;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/docent")
@Api(tags = "讲师接口(后台)")
public class DocentController {

    @Autowired
    private IDocentService docentService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = " 试讲/晋升详情(后台)", notes = " 试讲/晋升详情(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "selectDocentTrialDetail/{docentTrialId}", method = RequestMethod.POST)
    public ReturnVO selectDocentTrialDetail(@PathVariable Long docentTrialId) {
        return docentService.selectDocentTrialDetail(docentTrialId);
    }

    @ApiOperation(value = " 讲师列表/试讲列表/晋升列表(后台)", notes = " 讲师列表/试讲列表/晋升列表(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listDocent", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Docent>>> listDocent(@RequestHeader String token, @RequestBody DocentDto docentDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return docentService.listDocent(jsonObject.getLong("enterpriseId"), docentDto);
    }

    @ApiOperation(value = " 讲师列表(企业详情)(后台)", notes = "讲师列表(企业详情)(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listDocent4enterpriseDetail", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Docent>>> listDocent4enterpriseDetail(@RequestHeader String token, @RequestBody DocentDto docentDto) {
        return docentService.listDocent(docentDto.getEnterpriseId(), docentDto);
    }

    @ApiOperation(value = "平台列出全部企业讲师(后台)", notes = "平台列出全部企业讲师(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listDocentAllEnterprise", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Docent>>> listDocentAllEnterprise(@RequestHeader String token, @RequestBody DocentApplyDto docentApplyDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return docentService.listDocentAllEnterprise(docentApplyDto);
    }

    @ApiOperation(value = "讲师申请列表(后台)", notes = "讲师申请列表(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listDocentApply", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<DocentApply>>> listDocentApply(@RequestHeader String token, @RequestBody DocentApplyDto docentApplyDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return docentService.listDocentApply(jsonObject.getLong("enterpriseId"), docentApplyDto);
    }

    @ApiOperation(value = " 讲师申请通过(后台)", notes = " 提交讲师申请(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "passDocentApply", method = RequestMethod.POST)
    public ReturnVO passDocentApply(@RequestHeader String token, @RequestBody PassDocentApplyDto passDocentApplyDto) {
        AdminUser adminUser = JSONObject.parseObject(redisTemplate.opsForValue().get(token), AdminUser.class);
        return docentService.passDocentApply(adminUser, passDocentApplyDto);
    }

    @ApiOperation(value = " 讲师申请失败(后台)", notes = " 讲师申请失败(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "failDocentApply", method = RequestMethod.POST)
    public ReturnVO failDocentApply(@RequestHeader String token, @RequestBody FailDocentApplyDto failDocentApplyDto) {
        AdminUser adminUser = JSONObject.parseObject(redisTemplate.opsForValue().get(token), AdminUser.class);
        return docentService.failDocentApply(adminUser, failDocentApplyDto);
    }

    @ApiOperation(value = " 添加或修改企业讲师(后台)", notes = " 添加或修改企业讲师(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "sendDocent", method = RequestMethod.POST)
    public ReturnVO sendDocent(@Valid @RequestBody DocentInsDto docentInsDto) {
        return docentService.sendDocent(docentInsDto);
    }

    @ApiOperation(value = " 根据讲师id删除讲师(后台)", notes = " 根据讲师id删除讲师(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "deleteDocentById/{docentId}", method = RequestMethod.POST)
    public ReturnVO deleteDocentById(@PathVariable Long docentId) {
        return docentService.deleteDocentById(docentId);
    }

    @ApiOperation(value = " 添加或修改平台讲师(后台)", notes = " 添加或修改平台讲师(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "saveDocent", method = RequestMethod.POST)
    public ReturnVO saveDocent(@Valid @RequestBody DocentInsDto docentInsDto) {
        return docentService.saveDocent(docentInsDto);
    }

    @ApiOperation(value = " 发布或修改试讲试讲(后台)", notes = " 发布或修改试讲试讲(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "saveDocentTrial", method = RequestMethod.POST)
    public ReturnVO saveDocentTrial(@RequestBody DocentTrial docentTrial) {
        return docentService.saveDocentTrial(docentTrial);
    }

    @ApiOperation(value = " 试讲内部列表(后台)", notes = " 试讲内部列表(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listDocentTrial", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<DocentTrial>>> listDocentTrial(@RequestBody DocentTrialDto docentTrialDto) {
        return docentService.listDocentTrial(0, docentTrialDto);
    }

    @ApiOperation(value = "晋升内部列表(后台)", notes = " 试讲内部列表(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listPromotion", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<DocentTrial>>> listPromotion(@RequestBody DocentTrialDto docentTrialDto) {
        return docentService.listDocentTrial(1, docentTrialDto);
    }

    @ApiOperation(value = "试讲发布至晋升(后台)", notes = "试讲发布至晋升", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "sendDocentTrialToPromotion/{docentTrialId}", method = RequestMethod.POST)
    public ReturnVO sendDocentTrialToPromotion(@PathVariable Long docentTrialId) {
        return docentService.sendDocentTrialToPromotion(docentTrialId);
    }

    @ApiOperation(value = " 讲师工具列表(后台)", notes = " 讲师工具列表(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listDocentTool", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<DocentTool>>> listDocentTool(@RequestHeader String token, @RequestBody DocentToolDto docentToolDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return docentService.listDocentTool(jsonObject.getLong("enterpriseId"), docentToolDto);
    }

    @ApiOperation(value = " 添加讲师工具(后台)", notes = " 添加讲师工具(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "saveDocentTool", method = RequestMethod.POST)
    public ReturnVO saveDocentTool(@RequestHeader String token, @RequestBody DocentTool docentTool) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        docentTool.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return docentService.saveDocentTool(docentTool);
    }

    @ApiOperation(value = " 修改讲师工具(后台)", notes = " 修改讲师工具(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "updateDocentTool", method = RequestMethod.POST)
    public ReturnVO updateDocentTool(@RequestBody DocentTool docentTool) {
        return docentService.updateDocentTool(docentTool);
    }

    @ApiOperation(value = " 审核晋升(后台)", notes = " 审核晋升(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "updateDocentTrial", method = RequestMethod.POST)
    public ReturnVO updateDocentTrial(@Valid @RequestBody UpdateDocentTrialDto updateDocentTrialDto) {
        return docentService.updateDocentTrial(updateDocentTrialDto);
    }

    @ApiOperation(value = " 查询讲师详情(后台)", notes = " 查询讲师详情(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "selectDocentDetail/{docentId}", method = RequestMethod.POST)
    public ReturnVO<Docent> selectDocentDetail(@PathVariable Long docentId) {
        return docentService.selectDocentDetail(docentId);
    }


}
